Skip to content

Optimize DeployToGrafana - #2359

Merged
cedric-cordenier merged 5 commits into
mainfrom
add-parallelism
Sep 7, 2026
Merged

Optimize DeployToGrafana#2359
cedric-cordenier merged 5 commits into
mainfrom
add-parallelism

Conversation

@cedric-cordenier

@cedric-cordenier cedric-cordenier commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Addresses three inefficiencies in the current implementation of DeployToGrafana:

  • Previously, each alert generated a call to UpdateAlertRule, serially. Now this happens in parallel according to the defined concurrency factor.
  • getAlertRules had N+1 calls to grafana to fetch the alert rules. The current implementation fetches all the alert rules up front and does in-memory filtering instead.
  • DeployCache allows composite deployments to share calls to populate invariants like resolving the dashboard folder and its alert rules

Both of these improvements have reduced the latency for the CRE observability dashboards by 50%.

Copilot AI lite review requested due to automatic review settings September 7, 2026 14:00
@cedric-cordenier
cedric-cordenier requested a review from a team as a code owner September 7, 2026 14:00
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

👋 cedric-cordenier, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

✅ API Diff Results - github.com/smartcontractkit/chainlink-common/observability-lib

✅ Compatible Changes (3)

grafana (1)
  • DeployCache — ➕ Added
grafana.DeployOptions (2)
  • Cache — ➕ Added

  • Concurrency — ➕ Added


📄 View full apidiff report

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

There is a confirmed goroutine loop-variable capture bug in parallelFor, and getAlertRules can return duplicate rules leading to failing double-deletes/updates.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR improves Observability.DeployToGrafana performance by (1) parallelizing alert-rule upserts with a bounded concurrency limit and (2) removing N+1 Grafana alert-rule fetches by downloading the full rule list once and filtering in-memory.

Changes:

  • Add a generic parallelFor helper (bounded concurrency via errgroup.SetLimit) and internal tests.
  • Fetch alert rules once per deploy (GetAlertRules) and filter locally instead of calling per-scope helper endpoints repeatedly.
  • Upsert alert rules concurrently with a new DeployOptions.Concurrency (defaulting to 8).
File summaries
File Description
observability-lib/grafana/parallel.go Adds a bounded-concurrency helper used to fan out alert-rule writes.
observability-lib/grafana/parallel_internal_test.go Unit tests for the new parallel helper.
observability-lib/grafana/dashboard.go Uses bounded parallelism for alert writes; optimizes alert-rule discovery by fetching once and filtering.
observability-lib/grafana/dashboard_deploy_test.go Integration-style test verifying single fetch + concurrent writes against a fake Grafana server.
observability-lib/go.mod Adds golang.org/x/sync dependency for errgroup.
observability-lib/go.sum Adds checksums for the new golang.org/x/sync dependency.
Review details
  • Files reviewed: 5/6 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread observability-lib/grafana/parallel.go
Comment thread observability-lib/grafana/dashboard.go Outdated
Comment thread observability-lib/grafana/dashboard.go
Comment thread observability-lib/grafana/parallel.go
@cedric-cordenier
cedric-cordenier force-pushed the add-parallelism branch 2 times, most recently from 3289dc7 to c889ae4 Compare September 7, 2026 14:49
Addresses two inefficiencies in the current implementation of DeployToGrafana:
* Previously, each alert generated a call to UpdateAlertRule, serially. Now this happens in parallel according to the defined concurrency factor.
* getAlertRules had N+1 calls to grafana to fetch the alert rules. The current implementation fetches all the alert rules up front and does in-memory filtering instead.
* Add a DeployCache to memoize fetching of folders and alert rules.

Both of these improvements have reduced the latency for the CRE observability dashboards by 50%.
@cedric-cordenier cedric-cordenier changed the title Add parallelism Optimize DeployToGrafana Sep 7, 2026
@cedric-cordenier
cedric-cordenier added this pull request to the merge queue Sep 7, 2026
Merged via the queue into main with commit b4860dd Sep 7, 2026
33 checks passed
@cedric-cordenier
cedric-cordenier deleted the add-parallelism branch September 7, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants